using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.DirectX.DirectDraw;
using System.Drawing;

namespace TowerDefense_Dx.Core
{
    public class DxSprite:DxImage
    {
        #region khai bao bien
        protected PointF _position;

        public PointF Position
        {
            get { return _position; }
            set { _position = value; }
        }
        protected PointF _center;
        public PointF Center
        {
            get { return _center; }
            set { _center = value; }
        }
        protected int _frameWidth;
        public int FrameWidth
        {
            get { return _frameWidth; }
            set { _frameWidth = value; }
        }
        protected int _frameHeight;
        public int FrameHeight
        {
            get { return _frameWidth; }
            set { _frameWidth = value; }
        }
        protected int _rows;
        public int Rows
        {
            get { return _rows; }
            set { _rows = value; }
        }
        protected int _columns;
        public int Columns
        {
            get { return _columns; }
            set { _columns = value; }
        }
        public int TotalFrame
        {
            get { return _rows * _columns; }
        }
        #endregion

        public DxSprite(string imagePath, Device graphicDevice, int frameWidth, int frameHeight):
            base(imagePath, graphicDevice)
        {
            _frameWidth = frameWidth;
            _frameHeight = frameWidth;
            GetTotalFrame();
        }
        protected void GetTotalFrame()
        {
            _rows = _sourceImage.Height / _frameHeight;
            _columns = _sourceImage.Width / _frameWidth;
        }
        public virtual void DrawFast(int x, int y, int frameIndex, Surface destSurface, DrawFastFlags flag)
        {
            int column = (frameIndex - 1) % _columns;
            int row = (frameIndex - 1) / _columns;
            Rectangle scrRec = new Rectangle(column * _frameWidth, row * _frameHeight, _frameWidth, _frameHeight);
            destSurface.DrawFast(x, y, _image, scrRec, flag);
           
        }
    }

}
